package Socket;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server2 {
    private ServerSocket serverSocket;
    public Server2(){
        try {
            System.out.println("正在启动服务端...");
            serverSocket =new ServerSocket(8080);
            System.out.println("服务端启动完毕...");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public void start(){
        try {
            System.out.println("等待客户端链接...");
            Socket socket=serverSocket.accept();
            System.out.println("一个客户端连接了!");
            InputStream in=socket.getInputStream();
            int d=in.read();
            System.out.println("客户端发送的数据是："+d);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        Server2 server=new Server2();
        server.start();
    }
}
